﻿<Page
    x:Class="IoTCoreMenu.SerialTerminalPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:IoTCoreMenu"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>
        <CollectionViewSource x:Name="DeviceListSource"/>
    </Page.Resources>

    <Grid>
        <Grid.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#7FFFFFFF" Offset="0.008"/>
                <GradientStop Color="#FF64EE15" Offset="1"/>
            </LinearGradientBrush>
        </Grid.Background>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <TextBlock Grid.Row="0" Grid.ColumnSpan="2" x:Name="MyTitle" HorizontalAlignment="Left" Height="23" Margin="10" TextWrapping="NoWrap"  Text="Universal Windows Generic Bluetooth Serial Test App " VerticalAlignment="Top" Width="800"/>
        <TextBlock Grid.Row="1" Grid.ColumnSpan="2" x:Name="uartTitle" Text="UART Setup" Style="{StaticResource HeaderTextBlockStyle}" 
                        IsHitTestVisible="false" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10,10,0,0"/>

        <StackPanel Grid.Row="2" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal" Margin="10,10,0,0">
            <TextBlock Text="Select Device:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
        </StackPanel>

        <StackPanel Grid.Row="4" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Top" Orientation="Horizontal" Margin="10,0,0,0" Width="300" Height="120">
            <ListBox x:Name="ConnectDevices" ItemsSource="{Binding Source={StaticResource DeviceListSource}}" Width="300" Height="80" Background="Gray" DoubleTapped="ConnectDevices_DoubleTapped">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Id}" />
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </StackPanel>

        <StackPanel Grid.Row="4" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Orientation="Vertical" Margin="30,0,0,0" Height="120" Width="94">
            <Button Name="comPortInput" Content="Connect" Click="comPortInput_Click"/>
            <Button Name="closeDevice" Margin="0,10,0,0" Content="Disconnect" Click="closeDevice_Click" IsEnabled="False" />
            <Button Name="refresh" Margin="0,10,0,0" Content="Refresh" Click="refreshDevice_Click" IsEnabled="True"/>
        </StackPanel>

        <StackPanel Grid.Row="5" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal" Margin="10,10,0,0">
            <TextBlock Text="Write Data:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
        </StackPanel>

        <StackPanel Grid.Row="6" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Top" Orientation="Horizontal" Margin="10,0,0,0" Width="300" Height="80">
            <TextBox Name="sendText" Width="300" Height="80"/>
        </StackPanel>

        <StackPanel Grid.Row="6" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Orientation="Vertical" Margin="30,0,0,0">
            <Button Name="sendTextButton" Content="Write" Click="sendTextButton_Click" Margin="5"/>
            <Button Name="cancelSendButton" Content="Cancel" Click="cancelSendTextButton_Click" Margin="5" IsEnabled="False"/>
        </StackPanel>

        <StackPanel Grid.Row="7" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal" Margin="10,10,0,0">
            <TextBlock Text="Read Data:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
        </StackPanel>

        <StackPanel Grid.Row="8" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal" Margin="10,0,0,0" Width="300" Height="80">
            <TextBox Name="recvdText" Width="300" Height="80"/>
        </StackPanel>

        <StackPanel Grid.Row="9" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10,20,0,0" Width="460" Height="40">
            <TextBox
                x:Name="status" TextWrapping="Wrap" IsReadOnly="True" Width="460" Height="40" HorizontalAlignment="Left" VerticalAlignment="Top" 
                ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" BorderBrush="White"/>
        </StackPanel>
        <StackPanel Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Orientation="Horizontal" Margin="10">
            <Button Name="backButton" Content="Back" Click="backButton_Click" Margin="20"/>
        </StackPanel>
    </Grid>
</Page>

